package com.cyandpos.pad.offline.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cyandpos.pad.R;

import java.util.HashMap;
import java.util.List;

public class DbAdapter extends BaseAdapter {
    List<HashMap<String,Object>> list;
    Context context;
    public DbAdapter( List<HashMap<String,Object>> list,Context context){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public HashMap<String,Object> getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_db_data,null);
            holder=new Holder();
            holder.tv_table=convertView.findViewById(R.id.tv_table);
            holder.tv_sums=convertView.findViewById(R.id.tv_sums);
            holder.tv_tm=convertView.findViewById(R.id.tv_tm);
            convertView.setTag(holder);
        }else{
            holder= (Holder) convertView.getTag();
        }
        HashMap<String,Object> map=getItem(position);
        if(map!=null){
            holder.tv_table.setText(map.get("table")+"");
            holder.tv_sums.setText(map.get("sum")+"");
            holder.tv_tm.setText(map.get("tm")+"");
        }
        return convertView;
    }

    class Holder{
        private TextView tv_table;
        private TextView tv_sums;
        private TextView tv_tm;
    }
}
